<template>
<view class="discounts-rules">
  <view class="discounts-rules-item" v-for="(rule,index) in ruleList" :key="rule.id">
    <view class="title">
      <!-- {{ rule.ruleName }} -->
      {{ index == 0? `集市折扣：${discount.market !==0?`${discount.market *10}折`:"暂未领取到折扣"  }`: `荣耀权益商城折扣：${discount.shops !==0?`${discount.shops * 10}折`:"暂未领取到折扣"}` }}
    </view>
    <view class="content">
      <!-- {{ rule.ruleInfo }} -->
      {{ rule.filedName }}
    </view>
    <up-cell
	    size="large"
	    title="查看更多"
	    isLink
      :name="rule.id"
      @click="headelCellClick"
	></up-cell>
  </view>
</view>
</template>
<script setup>
import {ref} from 'vue'
import {getDiscountsRulesApi,getConfigEnterpriseFieldsApi,getUserDiscountApi} from "@/api/user/index";
import {onShow} from "@dcloudio/uni-app";
import {customNav} from "@/utils/customNav";
// import { getUserDiscountApi } from "@/package_payment/pages/api/payment.js"

const discount = ref({
  market: 0,
  shops: 0,
})
const ruleList = ref([])
const getConfigEnterpriseFields = async () => {
  const res = await getConfigEnterpriseFieldsApi("权益规则");
  console.log("getConfigEnterpriseFieldsApi",res);
  const {code, data} = res
  if (code === 200) {
    console.log(data)
    ruleList.value = data[0].children
  }
}
function headelCellClick (data) {
  console.log(data);
  customNav(`discount-details?name=${data.name}`)
}
async function getUserDiscount () {
  const res =await getUserDiscountApi();
  console.log(res);
  const { code,data} =res ||{}
  if (code == 200) {
    discount.value.market = data.discount;
    discount.value.shops = data.storeDiscount;
  }
  
}
onShow(() => {
  getUserDiscount();
  getConfigEnterpriseFields()
})
</script>
<style scoped lang=less>
@import url(./less/discounts.less);
</style>
